package org.wyf.EveryPoint.crowd.service.impl;

import org.wyf.EveryPoint.common.entity.QueryRequest;

import org.wyf.EveryPoint.crowd.entity.Reward;
import org.wyf.EveryPoint.crowd.mapper.RewardMapper;
import org.wyf.EveryPoint.crowd.service.IRewardService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * 回报设置 Service实现
 *
 * @author wyf
 * @date 2021-04-09 16:56:39
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class RewardServiceImpl extends ServiceImpl<RewardMapper, Reward> implements IRewardService {

    private final RewardMapper rewardMapper;

    @Override
    public IPage<Reward> findRewards(QueryRequest request, Reward reward) {
        LambdaQueryWrapper<Reward> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<Reward> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }

    @Override
    public List<Reward> findRewards(Reward reward) {
	    LambdaQueryWrapper<Reward> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createReward(Reward reward) {
        this.save(reward);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateReward(Reward reward) {
        this.saveOrUpdate(reward);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteReward(Reward reward) {
        LambdaQueryWrapper<Reward> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}
}
